#!/bin/bash

cd $(adapt query self bld)

transf_opts=$(adapt oop self decode_options)

# clean installation before changes, also remove cmake cache as it may have sth implicitly set
rm -rf CMake*
<install_manifest.txt xargs -L1 rm -rf

# MPI_ENABLED must be on, otherwise zoltan freaks out
# in serial mode they copy mpi.h to include without checking if 
# the org. mpi.h file exists or not
adapt cmake \
  -D CMAKE_BUILD_TYPE:STRING=RELEASE \
  -D CMAKE_INSTALL_PREFIX:STRING=$(adapt query sys/prefix) \
  -D TPL_ENABLE_BLAS:BOOL=ON \
  -D TPL_ENABLE_LAPACK:BOOL=ON \
  -D TPL_ENABLE_MPI:BOOL=ON \
  $transf_opts ..


#  -D BLAS_LIBRARY_DIRS=$(adapt query lib/blas lib) \
#  -D BLAS_LIBRARY_NAMES=$(adapt query lib/blas libs) \

#  -D LAPACK_LIBRARY_DIRS=$(adapt query lib/lapack lib) \
#  -D LAPACK_LIBRARY_NAMES=$(adapt query lib/lapack libs) \

echo adapt cmake \
  -D CMAKE_BUILD_TYPE:STRING=RELEASE \
  -D CMAKE_INSTALL_PREFIX:STRING=$(adapt query sys/prefix) \
  -D TPL_ENABLE_MPI:BOOL=ON \
  -D TPL_ENABLE_BLAS:BOOL=ON \
  -D TPL_ENABLE_LAPACK:BOOL=ON \
  -D TPL_ENABLE_HDF5:BOOL=ON \
  -D TPL_ENABLE_ParMETIS:BOOL=ON \
  -D ParMETIS_LIBRARY_NAMES:STRING=parmetis \
  -D TPL_ENABLE_UMFPACK:BOOL=ON \
  -D TPL_ENABLE_AMD:BOOL=ON \
  -D TPL_ENABLE_Boost:BOOL=ON \
  -D TPL_ENABLE_Zlib:BOOL=ON \
  -D TPL_ENABLE_Pthread:BOOL=ON \
  -D Trilinos_ENABLE_Teuchos:BOOL=ON \
  -D Trilinos_ENABLE_Epetra:BOOL=ON \
  -D Trilinos_ENABLE_EpetraExt:BOOL=ON \
  -D Trilinos_ENABLE_Zoltan:BOOL=ON \
  -D Trilinos_ENABLE_AztecOO:BOOL=ON \
  -D Trilinos_ENABLE_Belos:BOOL=ON \
  -D Trilinos_ENABLE_Anasazi:BOOL=ON \
  -D Trilinos_ENABLE_Amesos:BOOL=ON \
  -D Trilinos_ENABLE_Ifpack:BOOL=ON \
  -D Trilinos_ENABLE_ML:BOOL=ON \
  -D Trilinos_ENABLE_NOX:BOOL=ON \
  -D Trilinos_ENABLE_Rythmos:BOOL=ON \
  -D Trilinos_ENABLE_Thyra:BOOL=ON \
  -D Trilinos_NO_64BIT_GLOBAL_INDICES:BOOL=ON \
  $src

adapt make -j $(adapt query sys/cpunum)

adapt make install
